/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JNewGroupDialog.java
 *
 * Created on 2009-9-13, 9:45:59
 */

package com.openbravo.pos.sales.restaurant;

import cn.ekuma.swing.dialog.AbstractKeyBoardJDialog;
import com.openbravo.pos.base.AppLocal;


import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import javax.swing.JFrame;

/**
 * @author Administrator
 */
public class JNewGroupDialog extends AbstractKeyBoardJDialog {

    private boolean isOK;
    private String groupName;

    /**
     * Creates new form JNewGroupDialog
     */
    public JNewGroupDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);

    }

    /**
     * Creates new form JTicketsBagSharedList
     */
    private JNewGroupDialog(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
    }

    public void init() {
        initComponents();
        isOK = false;
        groupName = "";
        jGroupName.setText(groupName);
    }


    public static JNewGroupDialog getDialog(Component parent) {

        Window window = getWindow(parent);

        JNewGroupDialog myreceiptsplit;

        if (window instanceof Frame) {
            myreceiptsplit = new JNewGroupDialog((Frame) window, true);
        } else {
            myreceiptsplit = new JNewGroupDialog((Dialog) window, true);
        }

        myreceiptsplit.init();
        return myreceiptsplit;
    }

    protected static Window getWindow(Component parent) {
        if (parent == null) {
            return new JFrame();
        } else if (parent instanceof Frame || parent instanceof Dialog) {
            return (Window) parent;
        } else {
            return getWindow(parent.getParent());
        }
    }

    public String getGroupName() {
        return groupName;
    }

    public boolean isOK() {
        return isOK;
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        m_jButtonOK = new javax.swing.JButton();
        m_jButtonCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jGroupName = new javax.swing.JTextField();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        m_jButtonOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png"))); // NOI18N
        m_jButtonOK.setText(AppLocal.getIntString("Button.OK")); // NOI18N
        m_jButtonOK.setFocusPainted(false);
        m_jButtonOK.setFocusable(false);
        m_jButtonOK.setMargin(new java.awt.Insets(8, 16, 8, 16));
        m_jButtonOK.setRequestFocusEnabled(false);
        m_jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jButtonOKActionPerformed(evt);
            }
        });
        jPanel2.add(m_jButtonOK);

        m_jButtonCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png"))); // NOI18N
        m_jButtonCancel.setText(AppLocal.getIntString("Button.Cancel")); // NOI18N
        m_jButtonCancel.setFocusPainted(false);
        m_jButtonCancel.setFocusable(false);
        m_jButtonCancel.setMargin(new java.awt.Insets(8, 16, 8, 16));
        m_jButtonCancel.setRequestFocusEnabled(false);
        m_jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_jButtonCancelActionPerformed(evt);
            }
        });
        jPanel2.add(m_jButtonCancel);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 60));

        jLabel2.setText(AppLocal.getIntString("label.newGroupName")); // NOI18N
        jLabel2.setPreferredSize(new java.awt.Dimension(80, 15));
        jPanel1.add(jLabel2);

        jGroupName.setPreferredSize(new java.awt.Dimension(80, 23));
        jPanel1.add(jGroupName);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width - 342) / 2, (screenSize.height - 229) / 2, 342, 229);
    }// </editor-fold>//GEN-END:initComponents

    private void m_jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonOKActionPerformed
        groupName = jGroupName.getText();
        if (!groupName.isEmpty())
            isOK = true;
        dispose();
    }//GEN-LAST:event_m_jButtonOKActionPerformed

    private void m_jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jButtonCancelActionPerformed

        dispose();
    }//GEN-LAST:event_m_jButtonCancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField jGroupName;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton m_jButtonCancel;
    private javax.swing.JButton m_jButtonOK;
    // End of variables declaration//GEN-END:variables

    @Override
    protected void enterKeyProc() {
        if (this.m_jButtonOK.isEnabled())
            m_jButtonOKActionPerformed(null);
    }

    @Override
    protected void escapeKeyProc() {
        dispose();
    }

    @Override
    protected void upKeyProc() {
    }

    @Override
    protected void downKeyProc() {
    }

}
